<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue.directive</title>
    <script type="text/javascript" src="../assets/js/vue.js"></script>
</head>
<body>
<h1>helloWorld</h1>
<hr>
<div id="app">
   <div v-jspang ="color">{{num}}</div>
    <p><button @click="add">add</button></p>


    <p>
        <button onclick="unbind()">解绑</button>
    </p>
</div>
<script>
    function unbind(){//解绑
        app.$destroy();
    }

   /* Vue.directive("jspang",function (el,binding,vnode) {
        console.log(el);
        console.log(binding);
        console.log(vnode);
        el.style='color:'+binding.value;
    });*/
    //生命周期
    Vue.directive("jspang",{
        bind:function(el,binding,vnode){//被绑定
            console.log('1 - bind');
            el.style='color:'+binding.value;
        },
        inserted:function(){//绑定到节点
            console.log('2 - inserted');
        },
        update:function(){//组件更新
            console.log('3 - update');
        },
        componentUpdated:function(){//组件更新完成
            console.log('4 - componentUpdated');
        },
        unbind:function(){//解绑
            console.log('5 - unbind');
        }
    });

    var app=new Vue({
        el:'#app',
        data:{
            num:10,
            color:'green',
        },
        methods:{
            add:function () {
                this.num++;
            }
        }
    })
</script>
</body>
</html>